$(document).ready(function () {

  init();

  var json =[
               {
                   "id": 0,
                   "name": "张磊",
                   "fxnub":3,
                   "gznub":0,
                   "diancontxt": [
                       {
                           "zai": 1,
                           "zaicontxt": "浙江婺城法院回应庭长打人事件：法官家人安全受言语威胁"
                       },
                       {
                           "zai": 3,
                           "zaicontxt": "律师版“论语”：合伙人说给助理的21条絮语"
                       }
                   ]
               },
               {
                   "id": 1,
                   "name": "蔡和",
                   "fxnub":3,
                   "gznub":0,
                   "diancontxt": [
                       {
                           "zai": 2,
                           "zaicontxt": "P2P面临的三大挑战与三大机遇——评《关于促进互联网金融健康发展的指导意见》对P2P行业的影响"
                       },
                       {
                           "zai": 0,
                           "zaicontxt": "进行中 |【北京】搜狐旗下互联网金融平台－搜易贷招聘法务主管"
                       }
                   ]
               },
               {
                   "id": 240,
                   "name": "张坚如",
                   "fxnub":3,
                   "gznub":0,
                   "diancontxt": [
                       {
                           "zai": 0,
                           "zaicontxt": "工业用地协议出让：法条法理全梳理"
                       },
                       {
                           "zai": 1,
                           "zaicontxt": "浙江知识产权律师收入大揭秘，你是哪一档？"
                       }
                   ]
               },
               {
                   "id": 3,
                   "name": "陈刚",
                   "fxnub":3,
                   "gznub":2,
                   "diancontxt": [
                       {
                           "zai": 2,
                           "zaicontxt": "借款合同效力裁判规则十条"
                       },
                       {
                           "zai": 0,
                           "zaicontxt": "观点交锋：谁说十年后律师不需要“大所”"
                       }
                   ]
               },
               {
                   "id": 4,
                   "name": "邓益忠",
                   "fxnub":3,
                   "gznub":0,
                   "diancontxt": [
                       {
                           "zai": 3,
                           "zaicontxt": "待解决 |【天津】求天津武清区律师合作执行案件"
                       },
                       {
                           "zai": 0,
                           "zaicontxt": "何帆：藐视法庭罪的前世今生"
                       }
                   ]
               },
               {
                   "id": 5,
                   "name": "何诚",
                   "fxnub":3,
                   "gznub":0,
                   "diancontxt": [
                       {
                           "zai": 2,
                           "zaicontxt": "吸食毒品成瘾的治安处罚适用治安处罚法的案例"
                       },
                       {
                           "zai": 3,
                           "zaicontxt": "工会有什么作用？农民工加入公会有什么好处"
                       }
                   ]
               },
               {
                   "id": 36,
                   "name": "胡青林",
                   "fxnub":3,
                   "gznub":0,
                   "diancontxt": [
                       {
                           "zai": 0,
                           "zaicontxt": "夫妻间赠与房屋那些事赠与房屋不过户登记无效？"
                       },
                       {
                           "zai": 3,
                           "zaicontxt": "无民事行为能力人怎么离婚离婚协议可以反悔"
                       }
                   ]
               },
               {
                   "id": 22,
                   "name": "马丽",
                   "fxnub":3,
                   "gznub":0,
                   "diancontxt": [
                       {
                           "zai": 2,
                           "zaicontxt": "这九种情况闯红灯不违法发生交通事故后的正确做法"
                       },
                       {
                           "zai": 0,
                           "zaicontxt": "相对负刑事责任的案例分析刑事强制措施是什么？"
                       }
                   ]
               },
               {
                   "id": 8,
                   "name": "彭金",
                   "fxnub":3,
                   "gznub":0,
                   "diancontxt": [
                       {
                           "zai": 2,
                           "zaicontxt": "房屋买卖专业解决律师点评房屋买卖纠纷律师对一起借"
                       },
                       {
                           "zai": 1,
                           "zaicontxt": "女儿保卫战－争取抚养权"
                       }
                   ]
               },
               {
                   "id": 9,
                   "name": "苏余",
                   "fxnub":3,
                   "gznub":0,
                   "diancontxt": [
                       {
                           "zai": 21,
                           "zaicontxt": "劳动律师成功案例之拿到补"
                       },
                       {
                           "zai": 3,
                           "zaicontxt": "租赁合同中的拆迁补偿纠纷"
                       }
                   ]
               },
               {
                   "id": 230,
                   "name": "杨正华",
                   "fxnub":3,
                   "gznub":0,
                   "diancontxt": [
                       {
                           "zai": 2,
                           "zaicontxt": "酒后伤人，律师辩护获判缓"
                       },
                       {
                           "zai": 1,
                           "zaicontxt": "天津爆炸案政府回购房屋的法理阐述"
                       }
                   ]
               },
               {
                   "id": 103,
                   "name": "夏希",
                   "fxnub":3,
                   "gznub":0,
                   "diancontxt": [
                       {
                           "zai": 1,
                           "zaicontxt": "危害公共安全放火，律师辩"
                       },
                       {
                           "zai": 3,
                           "zaicontxt": "何某某诉潍坊某铝业有限公"
                       }
                   ]
               },
               {
                   "id": 12,
                   "name": "张江华",
                   "fxnub":3,
                   "gznub":0,
                   "diancontxt": [
                       {
                           "zai": 0,
                           "zaicontxt": "【合同纠纷】诉请协助解除"
                       },
                       {
                           "zai": 3,
                           "zaicontxt": "二手房交易业主反价是否能强制性要求其过户"
                       }
                   ]
               },
               {
                   "id": 163,
                   "name": "应晓伟",
                   "fxnub":3,
                   "gznub":0,
                   "diancontxt": [
                       {
                           "zai": 2,
                           "zaicontxt": "集资骗局，起诉还是报案？"
                       },
                       {
                           "zai": 0,
                           "zaicontxt": "盗窃辩护成功适用缓刑，少年得重生机会"
                       }
                   ]
               },
               {
                   "id": 232,
                   "name": "王磊",
                   "fxnub":3,
                   "gznub":0,
                   "diancontxt": [
                       {
                           "zai": 2,
                           "zaicontxt": "谁动了企业的“软件著作权”"
                       },
                       {
                           "zai": 3,
                           "zaicontxt": "无罪归来：2015年深圳龙岗首例“侵犯软件著作权"
                       }
                   ]
               },
               {
                   "id": 15,
                   "name": "汪德忠",
                   "fxnub":3,
                   "gznub":0,
                   "diancontxt": [
                       {
                           "zai": 1,
                           "zaicontxt": "2015首例侵犯软件著作权无罪不起诉--深圳知产"
                       },
                       {
                           "zai": 2,
                           "zaicontxt": "法尚正义:2015深圳龙岗区首例侵犯软件著作权无"
                       }
                   ]
               }
           ];
        

  $(".qz-left .qz-img li").hover(
      function () {
        $($(this)+":nth-child(4) .portraitB").css("border","2px solid #fff");
        $(this).children().children().css(" border","2px solid #004799");

        var index = $(this).index();
          $(".intruduction .texts li").remove();
          for(var i=0;i<json.length;i++){
            if(i == index){
              $(".intruduction #name").text(json[i].name);
              $(".intruduction #contxt").text(json[i].fxnub + "篇文章， " + json[i].gznub + "人关注他");
              //console.info(json[i].diancontxt.length)
              for(var j=0; j<json[i].diancontxt.length;j++){
                $(".intruduction .texts").append(
                        "<li><label>"+ json[i].diancontxt[j].zai + "</label><a href='javascript:void(0);'>"+ json[i].diancontxt[j].zaicontxt + "</a></li>"
                    );
              }
              break;
            }
          }
      },

      function () {
        $(".qz-left .qz-img li .portraitB").css("border","2px solid #fff");
        $(this).children().children().css("border","2px solid #004799");
      }
  );

   //圈子
   $(document).on( "click", ".addtoCircle", function(e) { 
      var layerWeiXinCode = '<div class="weixincode">'
          layerWeiXinCode+='<h3 class="distance">扫描二维码，关注律团微信，随时随地查看咨询动态！</h3>'
          layerWeiXinCode+='<img class="" src="'+jumpUrl+'/img/question/weixin.jpg" width="216" height="216" alt="" />'
          layerWeiXinCode+='<a href="' + jumpUrl + '"/question/list"><input type="button" class="inpbg viewIssues" value="查看问题"/></a>'
          layerWeiXinCode+='</div>';
      var loading = layer.msg('加载中...', {icon: 16});
      var weixincode = layer.open({
            type: 1, //基本层类型  可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）。 若你采用layer.open({type: 1})方式调用，则type为必填项（信息框除外）
            title: false, //标题
            closeBtn: true,  //关闭按钮
            shade:0.3,  //遮罩默认是0.3透明度
            shadeClose: false,  //是否点击遮罩关闭
            area: ['450px', '450px'],
            skin: 'yourclass', //样式类名
            content: layerWeiXinCode //内容
      });

      layer.close(loading);
      stopDefault(e);
      });
});

function init(){
     /*list article 最新文章*/
  var url_case_list = jumpUrl+"/lawyer/articles";
    $.get(url_case_list,function(data){
      
    }, "json").error(function(data) {
        layer.msg("请求失败！")
    }).success(function(data) {
        var obj = data.data;
        // console.info('obj',obj)
        var str ="";
        for(var i=0;i<obj.length; i++){
            var replaceTag = $('<div>').html(obj[i].info).text();
            if(replaceTag.length > 100){
             replaceTag = replaceTag.substr(0,100)+'...';
            }else{
              replaceTag = replaceTag;
            }
            str+='<li>'
                str+='<div class="newsimg">'
                str+='<a href="'+jumpUrl+'/lawyer/article/'+obj[i].id+'/view" title="'+obj[i].title+'">'
                  str+='<img class="" src="'+obj[i].img+'" width="198" height="129" alt="'+obj[i].title+'" /></div>'
                str+='</a>'
                str+='<div class="newstxt">'
                    str+='<h4 class="title"><a href="'+jumpUrl+'/lawyer/article/'+obj[i].id+'/view" title="'+obj[i].title+'">'+obj[i].title+'</a></h4>'
                    str+='<p class="wbtxt">'+replaceTag+'</p>'
                    str+='<a class="left" href="'+jumpUrl+'/lawyer/'+obj[i].creator_id+'">'+obj[i].realname+'</a>'
                    str+='<label class="right">'+(obj[i].created_at).substr(0,10)+'</label>'
                str+='</div>'
            str+='</li>';
    
        }
        $(".graphic").append(str);
    	  // $(".txtcenter span").text(obj[0].realname);
    	  // $(".txtcenter img").attr("src",obj[0].avatar);
    	  // $(".follow").text(obj[0].follows_count);
    	  // $(".hit").text(obj[0].hits);
    	  // $(".like").text(obj[0].likes);
       //  $(".graphic li").mousemove(function(){
       //  	var index = $(this).index();
       //  	$(".txtcenter span").text(obj[index].realname);
       //  	$(".txtcenter img").attr("src",obj[index].avatar);
       //  	$(".follow").text(obj[index].follows_count);
       //  	$(".hit").text(obj[index].hits);
       //  	$(".like").text(obj[index].likes);
       //  });
    })

    /*搜案例-列表 list_case */
    var url_list_article = jumpUrl+"/case/list_case?rows_per_page=2";
    $.get(url_list_article,function(data){
      
    }, "json").error(function(data) {
        layer.msg("请求失败！")
    }).success(function(data) {
        var obj = data.data;
        var str ="";
        for(var i=0;i<obj.length; i++){
          var replaceTag = $('<div>').html(obj[i].content).text();
          if(replaceTag.length > 100){
            replaceTag = replaceTag.substr(0,100)+'...';
          }else{
            replaceTag = replaceTag;
          }
          var title = obj[i].title;
          if (title.length > 25){
            title = title.substr(0,25)+'...';
          }
          str+='<h3>'+title+'</h3>'
          str+='<p>'+replaceTag+'</p><br>';
        }
        $(".list_articles1").append(str);
    })

    /*知识-列表 list_knowledge */
    var url_list_knowledge = jumpUrl+"/knowledge/list_knowledge?rows_per_page=2";
    $.get(url_list_knowledge,function(data){
      
    }, "json").error(function(data) {
        layer.msg("请求失败！")
    }).success(function(data) {
        var obj = data.data;
        var str ="";
        for(var i=0;i<obj.length; i++){
          var replaceTag = $('<div>').html(obj[i].content).text();
          if(replaceTag.length > 100){
            replaceTag = replaceTag.substr(0,100)+'...';
          }else{
            replaceTag = replaceTag;
          }
          var title = obj[i].title;
          if (title.length > 25){
            title = title.substr(0,25)+'...';
          }
          str+='<h3>'+title+'</h3>'
          str+='<p>'+replaceTag+'</p><br>';
        }
        $(".list_articles2").append(str);
    })

    //缺少学知识的接口
}

